#pragma region Copyright
/// <copyright>
/// Copyright (c) 2007 Ilia Shramko.
/// Released under the terms of the GNU Lesser General Public License.
/// </copyright>
#pragma endregion

#pragma once

class HttpRequest
{
public:
	int _refs;
	bool _isPost;
	CString _method;
	CString _url;
	CComSafeArray<BYTE> _content;
	HttpHeaderCollection _headers;

public:
	HttpRequest(const wchar_t* method, const wchar_t* url) : _refs(1)
	{
		ATLTRACE_TS(atlTraceIE, TraceLevel::Verbose, "[%p] HttpRequest::HttpRequest\r\n", this);
		_method = method;
		_url = url;
	}

	~HttpRequest()
	{
		ATLTRACE_TS(atlTraceIE, TraceLevel::Verbose, "[%p] HttpRequest::~HttpRequest\r\n", this);
	}

	int AddRef()
	{
		return ++_refs;
	}

	int Release()
	{
		if(--_refs == 0)
			delete this;
		return _refs;
	}

	const wchar_t* GetMethod()
	{
		return _method;
	}

	HttpHeaderCollection& GetHeaders()
	{
		return _headers;
	}

	CComSafeArray<BYTE>& GetContent()
	{
		return _content;
	}

	HRESULT AttachContent(SAFEARRAY* content, const wchar_t* contentEncoding)
	{
		HRESULT hr = _content.Attach(content);
		if(FAILED(hr)) return hr;
		if(contentEncoding != NULL)
		{
			_headers.Set(HeaderContentType, contentEncoding);
		}
		return hr;
	}

};

